package com.kuqi.dao;

import com.kuqi.entity.BookInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.sql.Date;
import java.util.List;

public interface BooksRepository extends JpaRepository<BookInfo, Integer> {
    // 根据类别来查询数据库数据
    @Query(value = "select * from books where book_type =  ?1 limit ?2",nativeQuery = true)
    List<BookInfo> findBooksByTypeWithLimit(int bookType, int num);

    // 注册一个新的用户
    @Modifying
    @Transactional
    @Query(value = "INSERT into books value(null,:bookName, :thumbnail, :describe, :author, :bookType, :updateDate)", nativeQuery = true)
    int insertValue(@Param("bookName") String bookName, @Param("thumbnail") String thumbnail,
                    @Param("describe") String describe, @Param("author") String author, @Param("bookType") int bookType,
                    @Param("updateDate") Date updateDate);

}